Cache immutable MCP source archives - #1792
Merged
Merged
Conversation
Contributor
ApprovabilityVerdict: Approved Simple performance optimization adding memoization to an internal tarball-creation helper. Changes are mechanical (list→tuple for hashability) with appropriate documentation of caching assumptions. You can customize Macroscope's approvability policy. Learn more. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 587e25d9fe
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Cache immutable source archives used to provision sandboxed MCP tool and user runtimes, avoiding repeated tar and gzip work within an eval worker.
Reasoning
Each sandbox launch uploads the same Verifiers checkout and environment package. Archive construction happens synchronously while evaluating the arguments to
runtime.write, before the coroutine can yield, so rebuilding an identical archive adds startup latency, blocks the event loop, and allocates a fresh compression buffer for every runtime.An eval worker already treats imported code as a startup snapshot. This change applies the same lifetime to its source archives:
VF_BUILD_INPUTSand the member selector become immutable tuples, and_tar_sourceis cached by source root plus member tuple. Different roots and filters remain distinct cache keys. Tar contents, exclusions, sandbox upload bytes, extraction, and installation behavior are unchanged.If development-time source mutation becomes a supported workflow, the cache should move to an explicit shorter lifecycle rather than refreshing process-global data implicitly.
Performance impact
A five-call repeated-build benchmark used the 624,058-byte Verifiers archive containing 353 tar members. Timings use
time.perf_counter; transient allocations usetracemalloc.The first build for each distinct key is unchanged. A cached key retains its immutable archive payload (624,058 bytes in this workload) for the worker lifetime, while upload volume remains unchanged.
Note
Low Risk
Process-local memoization only; tarball bytes and sandbox install paths are unchanged, with stale archives possible only if on-disk source changes mid-worker (already the eval snapshot model).
Overview
Caches gzipped source archives used when
_install_in_sandboxuploads the Verifiers checkout and env package, so repeated sandbox launches in the same worker do not rebuild identical tarballs on everyruntime.write._tar_sourceis wrapped withfunctools.cache, keyed by sourcePathand the member filter tuple.VF_BUILD_INPUTSand the default member list are tuples so they are hashable cache keys. Tar layout, exclusions, and upload/install behavior are unchanged.The docstring notes that archives are treated like the worker’s startup code snapshot; if live source edits become supported, the cache should move to an explicit shorter lifecycle instead of process-global reuse.
Reviewed by Cursor Bugbot for commit 587e25d. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Cache
_tar_sourceresults to avoid re-tarring identical MCP source archivesDecorates
_tar_sourcein launch.py with@functools.cacheso repeated calls with the same(src, members)arguments return cached bytes. Also convertsVF_BUILD_INPUTSfrom a list to a tuple to support hashability. Risk: passing a list formemberswill now raiseTypeErrorat call time due to cache key hashing requirements.Macroscope summarized 587e25d.